#include <iostream>
using namespace std;

//人类
class Human {
public:
	Human (const string& name, int age):m_name(name), m_age(age),m_id(1234) {}
	void eat (const string& food) {
		cout << "我在吃" << food << endl;
	}
	void sleep (int hour) {
		cout << "我睡了" << hour << "小时" << endl;
	}
protected:
	//保护的成员可以在类的内部和子类中进行访问
	string m_name;
	int m_age;
	const int& getID (void) const {
		return m_id;
	}
private:
	int m_id; //私有成员 身份证号
};

//学生类
class Student:public Human {
public:
	Student (const string& name, int age, int no):Human(name, age),m_no(no) {}
	void learn (const string& course) {
		cout << "我在学" << course << endl;
	}
	void who (void) 
	{
		cout << "我是" << m_name << ",今年" << m_age << "岁，学号" << m_no << endl;
		cout << "身份证号:" << getID () << endl;
	}
private:
	int m_no;
};

class Teacher:public Human {
public:
	Teacher (const string& name, int age, double salary):Human(name, age), m_salary(salary) {}
	void Teach (const string& course) {
		cout << "我在讲" << course << endl;
	}
	void who (void) 
	{
		cout << "我是" << m_name << ",今年" << m_age << "岁，工资" << m_salary << endl;
	}
protected:
	double m_salary;
};


int main (void)
{
	Student s("白云", 71, 10010);
	s.who ();
	s.eat ("土豆");
	s.sleep (2);
	s.learn ("二人转");

	Teacher t("黑土", 75, 400.23);
	t.who ();
	t.eat ("牛肉");
	t.sleep (12);
	t.Teach ("嵌入式");

	//Student * ---> Human *， 向上造型
	Human *ph = &s;
	ph->eat ("午餐");
	ph->sleep (1);
	//ph->learn ("C++"); //扩大范围的访问, 不安全

	Student* ps = static_cast <Student*>(ph);
	ps->who();
	
	//Human * ---> Stundet * 向下造型
	Human h ("林黛玉", 20);
	//Student *ps2 = &h; //向下造型, 危险
	Student *ps2 = static_cast <Student*> (&h);
	ps2->who();
	return 0;
}
